#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>

class Solution
{
    vector<vector<int>> ret;
    bool vis[8] = { false };
    vector<int> path;
public:
    vector<vector<int>> permuteUnique(vector<int>& nums)
    {
        sort(nums.begin(), nums.end());
        dfs(nums);
        return ret;
    }

    void dfs(vector<int>& nums)
    {
        if (path.size() == nums.size())
        {
            ret.push_back(path);
            return;
        }

        for (int i = 0; i < nums.size(); i++)
        {
            if (vis[i] == true || (i > 0 && (nums[i - 1] == nums[i]) && vis[i - 1] == false))
                continue;

            path.push_back(nums[i]);
            vis[i] = true;
            dfs(nums);
            vis[i] = false;
            path.pop_back();
        }
    }
};

int main()
{
    Solution s;
    vector<int> nums = { 1,1,2 };
    auto ret = s.permuteUnique(nums);
    return 0;
}